package April._20.work4;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Copy {
    public static void copyFile(File sourceFile, File targetFile) throws IOException {
        FileInputStream in = new FileInputStream(sourceFile);
        FileOutputStream out = new FileOutputStream(targetFile);
        long sourceSize = sourceFile.length();
        byte[] bytes = new byte[1024];
        int readCount;int sum=0,preSum=0;
        while((readCount=in.read())!=-1){
            out.write(bytes);
            sum+=readCount;
            if(sum-preSum>sourceSize/100){
                preSum=sum;
                System.out.println("sourceFile copied "+sum/sourceSize+"%");
            }
        }
        System.out.println("sourceFile copied 100%");
    }
}
